package com.example.testspringes.threadtest;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description: //TODO
 * @ProjectName: testspringes
 * @Package: com.example.testspringes.threadtest
 * @Author: FX
 * @CreateDate: 2019/4/1 14:41
 * @Version: 1.0
 * Copyright: Copyright (c) 2019
 */
@Component
public class TestAsyn {
    public static AtomicInteger atomicInteger2 = new AtomicInteger(0);

    @Async
    public  void tt()  {
        long a=System.currentTimeMillis();
        while (atomicInteger2.get()<100){
            atomicInteger2.getAndAdd(1);
            System.out.println(Thread.currentThread().getName()+"--"+atomicInteger2);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        long b=System.currentTimeMillis();
        System.out.println("耗时:"+(b-a));
    }
}
